System and method of high volume rule engine

ABSTRACT

A rule engine configured with at least one hash table which summarizes the rules managed by the engine. The rule engine receives rules and automatically adjusts the hash table in order to relate to added rules and/or in order to remove cancelled rules. The adjustment may be performed while the rule engine is filtering packets, without stopping. The rules may be grouped into a plurality of rule types and for each rule type the rule engine performs one or more accesses to at least one hash table to determine whether any of the rules of that type match the packet. In some embodiments, the rule engine may automatically select the rule types responsive to a set of rules provided to the rule engine and adapt its operation to the specific rules it is currently handling, while not spending resources on checking rule types not currently used.

RELATED APPLICATIONS

The present application is a continuation of, and claims the benefitpriority to, U.S. patent application Ser. No. 13/953,090, filed on Jul.29, 2013, the disclosure of which is incorporated by reference herein.

FIELD OF THE DISCLOSURE

The present disclosure relates generally to rule engines, andparticularly to real-time rule-engines required to operate with highthroughputs.

BACKGROUND OF THE DISCLOSURE

Packet based communication networks include nodes which perform varioustasks on the packets passing on the network. These tasks include, forexample, firewall access control, traffic routing, QoS (Quality ofService) implementation and traffic probing. As different packets arehandled differently, network nodes generally employ a rule engine whichis configured with rules for handling packets. Each rule identifies agroup of packets and indicates the handling to be applied to that groupof packets. Packets received by the node are compared to the rules untila match is found and then the handling indicated by the matching rule isapplied to the packet and generally to all subsequent packets belongingto the same session (referred to herein also as a packet connection).

When a rule engine needs to apply a large number of rules, itsperformance may suffer due to the time needed in order to check all therules, the amount of memory required and the increasing number of memoryaccesses, which are relatively slow operations.

U.S. Pat. No. 7,139,837 to Parekh et al. describes a rule engine whichtraverses a mesh having path nodes and path edges arranged in a treepart and graph part. The rule engine manages session entries forpackets, such that the rule checking performed for a first packet of asession can be used to speed up the handling of further packetsbelonging to the session.

U.S. Pat. No. 6,857,018 to Jiang describes using a multiple dimensionspatial indexing and mapping to speed up rule lookup in a table.

U.S. Pat. No. 8,005,945 to Cohen et al. describes adjusting the rules tosegregate their ranges and minimize the number of rules.

A paper titled: “Deep Packet Inspection using Parallel Bloom Filters”,by Sarang Dharmapurikar, Praveen Krishnamurthy Todd Sproull and JohnLockwood, Hot Interconnects 11, IEEE Computer Society, pp. 52-61,January 2004, suggests using Bloom filters to identify packets thatpotentially include predefined strings in their payload and then usingan independent process to eliminate false positives.

A paper titled: “Fast Pattern-Matching Techniques for Packet Filtering,by Alok S. Tongaonkar, Master of Science in Computer Science, StonyBrook University, May 2004, describes applying techniques for patternmatching in packet filtering systems.

A paper titled “Packet Classification for Core Routers: Is there anAlternative to CAMs?”, by Florin Baboescu, Sumeet Singh, GeorgeVarghese, IEEE Infocom, 2003, suggests filtering packets using a twodimensional filter on the IP source and destination addresses at a firststep and then searching through the received results.

US patent publication 2011/0102157 to Tarkoma describes using a Bloomfilter to filter out packets that should not be sent to a receiver.

US patent 2010/0195653 to Jacobson describes packet routing using alongest-prefix-match lookup engine which may be implemented using aTCAM, tree structure or Bloom filter.

US patent publication 2009/0182867 to Milliken et al. describes a methodof identifying malicious packets by comparing results of applying a hashfunction to packets with previously generated hash results of themalicious packets.

SUMMARY OF THE DISCLOSURE

An embodiment that is described herein provides a rule engine which isdesigned to check packets for a large number of rules at high speeds.

There is therefore provided in accordance with an embodiment of thepresent invention, a method of screening data packets for matching rulesby a processing unit, including receiving packets, by the processingunit, generating for each received packet, one or more first lookup keysfrom one or more fields of the packet, accessing, for the generated oneor more first lookup keys, a data structure which correlates between keyvalues and records indicating further acts to be performed indetermining whether a packet corresponding to the key value matches arule, wherein at least some of the records indicate one or more specifictests to be applied to the packet to determine whether the packetmatches a rule, which specific tests are adjusted to the value of thekey used in accessing the record, performing the further acts indicatedby the accessed record so as to determine whether the packet matches arule, and applying rules determined to match packets, to the matchingpackets.

Optionally, generating the one or more first lookup keys includesgenerating at least one first lookup key based on a plurality of fieldsof the packet.

Optionally, generating at least one of the lookup keys includesgenerating a key based on a result of applying an operator to one ormore fields of the packet.

Optionally, at least some of the records indicate one or more secondlookup keys to be used in one or more respective further accesses to thedata structure.

Optionally, at least some of the records in the data structure indicatea plurality of second lookup keys to be used in a further access to thedata structure.

Optionally, at least one first record indicates a single second lookupkey and at least one second record indicates a plurality of secondlookup keys. Optionally, the data structure includes a Hash table, aTRIE, a TCAM and/or a Bloom filter.

Optionally, the data structure includes for each lookup key:

an indication that there are no corresponding rules;

an indication of a rule record for a final determination of whether thepacket matches a specific rule; or

an indication of one or more additional lookup keys to be used inadditional accesses to the data structure.

Optionally, performing the further acts includes performing for a firstpacket a single additional access to the data structure resulting inaccessing a rule record and performing for a second packet an additionalaccess resulting in another additional access.

Optionally, generating for each received packet one or more first lookupkeys includes generating for one or more packet a plurality of differentfirst lookup keys.

Optionally, the accesses to the data structure for the plurality ofdifferent first keys of the packet are performed for all the first keyseven if a matching rule was already found for the packet.

Optionally, the method includes storing the results of the determinationof whether the packet matches a rule in a session flow table, for atleast some packet sessions, for further use on subsequently receivedpackets of the session.

Optionally, the method includes determining whether the packet belongsto a session recently handled and selecting a handling of the packet, ifdetermined to belong to a recently handled session, responsively to aprevious handling determined for the session.

Optionally, the method includes determining whether data structureentries were changed or added after a handling of a previously handledpacket of the session, and accordingly determining which first lookupkeys are generated and used in accessing the data structure.

Optionally, the method includes determining when a packet of the sessionwas first handled, and not using the handling previously determined forthe packet of the session, if a packet of the session was first handledbefore about a predetermined time.

Optionally, at least one of the records indicates a time at which anewly received packet is not to be handled based on a previous handlingdetermined for the session.

Optionally, the method includes changing the content of data structureentries as a function of time.

Optionally, the method includes receiving by a rule manager processorrules to be implemented and updating the data structure to implement thereceived rules, while the processing unit is receiving packets andaccessing the data structure, without locking the operation of theprocessing unit.

There is further provided in accordance with an embodiment of thepresent invention, a rule engine, including an input interface forreceiving packets, a memory unit configured with at least one datastructure correlating between packet key values and indications of rulesto be applied to packets having the respective key values, wherein forat least some packet key values the at least one data structure includesan indication of one or more keys to be used in further access to thedata structure, and a packet filtering processing unit configured toreceive packets, to generate for each packet at least one first lookupkey including one or more fields of the packet, to access the datastructure responsive to the generated at least one first lookup keys,and to perform the further acts indicated by the data structure for thepacket so as to determine whether the packet matches a rule.

Optionally, the data structure includes a TRIE and/or a TCAM.Optionally, the rule engine includes a rule manager processor configuredto receive rules to be implemented by the rule engine and to update thedata structure responsive to the received rules while the packetfiltering processing unit is operative, without locking the memory unitfor access by the packet filtering processing unit. Optionally, the rulemanager processor is configured to receive a plurality of rules, todivide the rules into rule types and to configure the packet filteringprocessing unit with instructions on generating the lookup keysaccording to the rule types.

Optionally, one or more of the lookup keys includes in addition to theone or more fields of the packet, one or more result fields includingresults of applying an operator to one or more fields of the packet.Optionally, the data structure includes a hash table.

Optionally, the packet filtering processing unit is configured toterminate accessing a hash table entry without accessing a correspondingkey of the entry, if the entry has a value indicating there are nomatching rules for the packet.

Optionally, the packet filtering processing unit is configured todetermine for the received packets whether they belong to a same packetconnection as a recently handled packet and to determine whether thepackets may be handled according to the handling of the recently handledpacket without accessing the data structure.

Optionally, the packet filtering processing unit is configured toidentify all the rules to which a received packet matches, continuing tosearch for matching rules to a packet even after a matching rule wasfound for the packet.

There is further provided in accordance with an embodiment of thepresent invention, a rule engine, including a memory unit configuredwith at least one hash table and with rule records and a packetfiltering processing unit configured to receive packets, to generate foreach packet a plurality of lookup keys, each including one or morefields of the packet, to access hash table entries responsive to thegenerated lookup keys, and to determine based on the accessed hash tableentries whether the packet matches a rule. The packet filteringprocessing unit is configured to determine whether there are matchingrules for each of the lookup keys, regardless of whether a matching rulewas found for any of the other lookup keys.

There is further provided in accordance with an embodiment of thepresent invention, a rule engine, including a memory unit configuredwith rules belonging to a plurality of groups, at least one datastructure which correlates between packets and matching rules, and atable which correlates between packet sessions and matching rules and apacket filtering processing unit configured to receive packets, todetermine for each packet a session to which the packet belongs, todetermine rules corresponding to a session of the packet from the table,to determine, for at least some packets, one or more groups of rules forwhich to access the at least one data structure to determinecorresponding rules from the group, and for the determined one or moregroups to access the at least one data structure with first lookup keyscorresponding to the groups. In determining the groups of rules forwhich to access the at least one data structure, the determination for afirst group is based on the time since the session was added to thetable.

Optionally, in determining the groups of rules for which to access theat least one data structure, the determination for a second group isbased on whether any of the rules of the second group changed since thesession was added to the table.

Optionally, the first and second groups correspond to the same firstlookup key. Optionally, in determining the groups of rules for which toaccess the at least one data structure, the determination for the firstgroup is performed regardless of whether rules of the group had changed.

The present disclosure will be more fully understood from the followingdetailed description of the embodiments thereof, taken together with thedrawings in which:

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram that schematically illustrates a rule engine,in accordance with an embodiment of the present disclosure;

FIG. 2 is a schematic illustration of data elements used by packetfilter, in accordance with an embodiment of the disclosure;

FIG. 3 is a flowchart of acts performed by a packet filter, inaccordance with an embodiment of the disclosure;

FIG. 4 is a flowchart of acts performed by rule manager in compilingrules, in accordance with an embodiment of the disclosure; and

FIG. 5 illustrates a rule handled by a rule manager, in accordance withan embodiment of the disclosure.

DETAILED DESCRIPTION OF EMBODIMENTS

An aspect of some embodiments relates to a rule engine configured withat least one hash table which summarizes the rules managed by theengine. The rule engine receives rules and automatically adjusts the atleast one hash table in order to relate to added rules and/or in orderto remove cancelled rules. The adjustment is optionally performed withinless than an hour, less than 10 minutes or even less than 1 minute fromreceiving the rule. In some embodiments, the adjustment is performedwhile the rule engine is filtering packets, without stopping thefiltering.

Optionally, the rules are grouped into a plurality of rule types and foreach rule type the rule engine performs one or more accesses to at leastone hash table, to determine whether any of the rules of that type matchthe packet. In some embodiments, the rule engine selects the rule typesresponsive to a set of rules provided to the rule engine, possibly evenresponsive to the set of rules with which the rule engine is currentlyconfigured. By automatically selecting the rule types, the rule engineadapts its operation to the specific rules it is currently handling,thus allowing the user a wide range of possible rules, while notspending resources on checking rule types not currently used.

In operation, the rule engine applies a hash function to one or moregroups of fields of received packets and accesses a hash table using aresulting hash key. The results of accessing the hash table determinethe rules that might be applied to the packets, possibly after furthertests. The use of a hash table which summarizes the rules allowsimplementation of a rule engine which can handle large numbers of rules,above 10,000, above 100,000 and even above a million rules, with a veryfast operation. The processing power required to scan a packet issubstantially constant, and does not substantially depend on the numberof rules configured to the rule engine. Scanning a packet for matchingrules of a specific rule type involves performing the same tasks andrequires the same amount of time, regardless of the number of rules ofthe type.

In some embodiments, the at least one hash table includes at least oneBloom filter. The term Bloom filter refers herein to a hash table inwhich entries provide a negative (e.g., null) answer for at least someaccesses to the hash table, without checking a key of the entry toverify that the entry actually corresponds to a key used to access theentry. In some embodiments, the hash table of the Bloom filter does notinclude keys in the entries at all. In other embodiments, the hash tableincludes keys in the entries but the key is accessed only if the entryhas a value which indicates a possibility of existence of one or morerules corresponding to the entry.

The hash table is optionally designed to be sufficiently large such thatmost entries, or even at least 90%, 99% or 99.9% of the entries, returna negative answer, according to an estimate of the largest number ofrules expected to be used. The size of the hash table is naturally, alsoa function of the available memory of the rule engine.

In some embodiments, for each rule type, only a single hash table accessis performed. Alternatively, for one or more of the rule types, possiblyeven for all the rule types, a series of accesses to one or more hashtables are performed, each access in the sequence being performed onlyif the previous access in the sequence did not indicate that nocorresponding rules are available. Optionally, the stages in thesequence do not receive any information from previous stages, except forthe knowledge that the present stage was reached, which indicates thatall the conditions leading to the current stage were met. Each entry isoptionally configured based on the conditions already met in previousstages.

In some embodiments, the series of accesses includes one or moreelimination stages in which non-matching rules are excluded withoutchecking whether the hash key has a match in the accessed hash tableentry, and one or more subsequent affirmation stages. In the affirmationstages, the hash key used to accessed the table is compared to acorresponding key in the entry and the entry is used only if the keysmatch. Optionally, the entry received in one of the accesses of thesequence indicates the packet fields to be used in performing the nextaccess of the sequence. The indication may be provided in a Bloom filterhash table and/or in a hash table in which key matching is affirmedbefore providing a result.

In some embodiments, a key used in accessing the hash table is formed ofone or more fields of the packet, possibly at least three fields or evenat least five fields of the packet. Alternatively or additionally, a keyused in accessing the hash table may include the result of applying oneor more operators to a field or fields of the packet. Using thisalternative, rules corresponding, for example, to inequalities, valueranges and/or a plurality of conditions in the alternative, may beimplemented. Optionally, the key used in accessing the hash table isconfigurable and is changed according to the set of rules currentlyhandled by the rule engine. In some embodiments, different keys are usedin accessing the hash table in different stages of checking a packet.

Optionally, the rule engine is formed of two separate components. Afirst component manages the rules and prepares them for implementationand a second component performs real time filtering with minimal writingor no writing at all. The two components optionally share a memory unitin a manner allowing them both to access the memory without locking.Optionally, an add-and-delete update method is used to update a hashtable in the memory. In implementing a rule change, the first componentoptionally puts entries required for a new version of the rule in memorylocations not accessible by the second component. When everything isready for utilization of the new version of the rule, a pointerdirecting to an old version of the rule is changed so that it points tothe new version of the rule and then the data entries of the old versionare cancelled.

An aspect of some embodiments relates to a rule engine configured tocheck received packets against all rules with which it is configured andto indicate all the rules that the packet matches and not just one ofthe matching rules.

System Overview

FIG. 1 is a block diagram that schematically illustrates a rule engine20, in accordance with an embodiment of the present disclosure. Ruleengine 20 includes a rule manager 22 and a packet filter 24. Rulemanager 22 receives rules through an input interface 32, compiles therules into an internal format of rule engine 20 and provides thecompiled rules through an output interface 34 to packet filter 24. Thecompiled rules are optionally stored in a memory 26 shared by rulemanager 22 and packet filter 24. In some embodiments, rule manager 22directly stores the compiled rules in memory 26.

Packet filter 24 receives packets through one or more input interfaces42 and determines for each packet whether there is a rule which pertainsto the packet. Optionally, packet filter 24 is configured to checkpackets for matching rules by performing one or more lookups in a hashtable. Optionally, each packet is checked for one or more rule typescorresponding to different sets of fields of the packet, forming alookup key into the hash table.

In some embodiments, rule manager 22 analyzes a set of rules with whichrule engine 20 is configured, to determine a set of rule types (andcorresponding lookup keys) for which each packet or stream of packets ischecked. In addition, rule manager 22 receives rules to be configuredinto packet filter 24, determines a rule type that the rule will beassociated with and accordingly configures the hash table and other datastructures in memory 26, as detailed hereinbelow.

As a short example, rule manager 22 receives the following set of ruleconditions:

Source IP=1.1.1.67 & VLAN=5

Source IP=2.2.1.67 & Dest Port=25

Destination IP=3.3.3.3 & VLAN=64 and source port=80

Source IP=2.2.1.2 & Dest Port=26 and protocol=62

Dest port=56 & VLAN=72

Rule manager 22 selects the following two rule types:

-   -   1) VLAN    -   2) Source IP & Dest Port        which cover the entire set of rules, as each rule can be        assigned to at least one of the rule types.

Rule manager 22 then assigns each rule to a rule type, configures thehash table with the portions of the rule covered by the rule type andconfigures memory 26 with the additional conditions that need to bechecked for those packets that match the portions of the rule matched bythe rule type. For example, the first rule is assigned to the rule typeof VLAN. The comparison of the VLAN field of the packet will be comparedto the value “5” in a hash table lookup, as discussed hereinbelow.Packets for which a match was found will be forwarded for furtherhandling in which Source-IP will be compared to the value 1.1.1.67.

Packets for which rules are found are handled by packet filter 24according to the rules, while packets for which rules were not found arehandled according to a default, for example are forwarded through adefault output interface 44. Packet filter 24 is generally designed tohandle a large number of packets, for example more than 1 millionpackets a second, more than 10 million packets a second, or even morethan 15 million packets a second.

Rule engine 20 may be used for various tasks, such as routing,classification (e.g., as described in US patent publication 2004/0095936to O'Neill et al.) and network security (e.g., as part of a firewall).For example, the rules may identify packets that are to be copied andforwarded through an additional output interface 46, in addition totheir being forwarded through output interface 44.

Packet filter 24 optionally performs all real time tasks of rule engine20, such that rule manager 22 has no real time tasks and can spendsufficient time and memory resources in order to achieve an optimalcompilation of the rules. In some embodiments, rule manager 22 mayperform the compilation with the aid of a human. In some embodiments,rule manager 22 manages hash table and/or other data structuremanagement information, such as information on the rule or rulescorresponding to each hash table entry, in a memory unit separate frommemory 26, reducing the amount of information that needs to be stored inmemory 26.

Rule manager 22 and/or packet filter 24 are implemented in hardware,software, firmware or combinations thereof. Rule manager 22 typicallycomprises one or more processors 50, memory units and required software,but may also comprise firmware or hardware. In some embodiments, rulemanager 22 is implemented by a general purpose computer. The softwaremay be downloaded to the processor in electronic form, over a network,for example. Alternatively or additionally, the software may be held ontangible, non-transitory storage media, such as optical, magnetic, orelectronic memory media. Packet filter 24 is optionally implemented by anetwork processor 48, although other types of processors, hardware,firmware or software based may be used. Packet filter 24 optionallyincludes one or more cache units 28.

Packet Filter

FIG. 2 is a schematic illustration of data elements used by packetfilter 24, in accordance with an embodiment of the disclosure. Packetfilter 24 manages a rule type list 202 which lists types of rules towhich packets (represented in FIG. 2 by a packet 220) need to becompared. For each rule type, rule engine 20 manages a type-record 204which defines the rule type and indicates the specific steps to be usedfor the rule type, as discussed herein below. Each type-record 204optionally also refers to a key structure 206, which defines the fields208 of packets 220, to be used in constructing a key 210 used indetermining whether the packet meets any of the rules of the rule type.A first hash function Hash1( ) is optionally applied to key 210 togenerate a hash key 212. A second hash function Hash2( ) is applied tohash key 212 in accessing a record in a hash table 214. The records ofhash table 214 indicate whether packets of the specific key providedhave a corresponding rule and what further handling should be applied tothe packet.

Alternatively or additionally to accessing hash table 214, hash key 212and the second hash function Hash2( ) are used to access a record in abloom filter 216, which indicates whether packets corresponding to thekey 210 may have a corresponding rule. Further elements shown in FIG. 2are discussed hereinbelow along with the discussion of the flowchart ofFIG. 3.

FIG. 3 is a flowchart of acts performed by packet filter 24, inaccordance with an embodiment of the disclosure. For each packet 220received (302), packet filter 24 optionally determines (330) whether thepacket belongs to a packet-connection for which a rule determination wasrecently performed. The determination (330) is optionally performed bysearching a table 230 of recently handled connections. In someembodiments, the determination is performed using any of the methodsdescribed in US patent application Ser. No. 13/357,482, titled Systemand Method for Flow Table Management, which is assigned to the assigneeof the present application and was filed Jan. 25, 2012.

If (330) the packet does not belong to a recently handled connection,packet filter 24 performs for each rule type (304A, 304B, 304C) withwhich it is configured, one or more (318) lookup stages (308) includingpreparing (306) a lookup key 210 and accessing (310) a hash table 214and/or a Bloom filter 216. The number of lookup stages (308) and theirdetails, such as which table is to be accessed in each stage (308), areoptionally set by the contents of the corresponding type-record 204. Thestages may be predetermined or may be dependent on the results ofprevious stages as discussed hereinbelow.

In lookup stages (308) which are last in a series or are a single stagefor a rule type, the table entry accessed, if (309) there is apossibility of a matching rule, indicates the further handling (312) ofthe packet, for example by a pointer to a rule record 272 in a ruledatabase 270. The further handling (312) in the rule record 272 mayindicate the rule to be applied (314) to the packet and/or may indicatefurther tests (316) that need to be applied to the packet to determinewhether it matches a rule. Lookup stages (308) followed by an additionalstage optionally determine whether to continue to the next stage. Insome embodiments, the result of an earlier stage in the series may alsoaffect the structure of the key 210 used in the following stage, inaddition to or instead of the key structure 206.

Lookup stages (308) are performed for all the rule types with which ruleengine 20 is configured and if (309) no match is found, the packet ishandled (322) according to a default handling.

In some embodiments, after handling (312) a packet according toinstructions in a corresponding table entry, the packet is not testedfor compliance with other rules, as rule manager 22 is configured tohave each packet correspond to at most a single rule. In otherembodiments, packet filter 24 checks for each packet all the types ofrules, even if a match is found. In still other embodiments, theinstructions in the corresponding table entry indicate whether to testthe packet for matching other types of rules.

If (330) a packet belongs to a recently handled packet connection, thepacket is optionally handled (332) according to the results of theprevious determination, as indicated in table 230, without performinglookup stages (308). In some embodiments, packet filter 24 checks beforethe handling (332), in a rematch act (335), whether recent changes inthe rules configured in packet filter 24 may require applying to thepacket a different handling than that prescribed by table 230. Rematchact (335) optionally determines the rule types for which changesoccurred, if any, and lookup stages (308) are performed only for thoserule types. The recent changes are optionally also checked to determinewhether a rule indicated for the packet connection by table 230 changed,in which case the handling (332) of that rule is not applied based onthe entry in table 230. If the rule needs to be applied to the packetdespite the change, it will be identified in the lookup stage 308corresponding to its rule type.

In some embodiments, table 230 indicates for each packet connectionrecently handled, the most recent time at which the rules correspondingto the packet connection were determined. A rule update list 232optionally lists rule types that were updated and their correspondingupdate times. Packet filter 24 optionally checks, in rematch act (335),for packets handled (332) according to listings in table 230, whethernew rules were added since the rules corresponding to the packetconnection were most recently determined. If there are one or more ruletypes which were updated since the most recent rule determination forthe connection, packet filter 24 performs lookup stages (308) for thepacket for these rule types. Table 230 is optionally periodicallyreviewed to remove old entries.

In some embodiments, packet filter 24 manages rule type list 202 orderedaccording to the time at which each rule type was last updated with anew rule. In handling received packets, packet filter 24 determines fromtable 230 the time at which the handling for the connection wasdetermined. Packet filter 24 then goes through ordered list 202 in theorder from the most recently changed rule type and for each rule typerecord 204 determines whether there was a change after the handling ofthe connection was most recently determined. If there was a change, alookup stage is performed for that rule type and the determination ofwhether there was a change after the handling of the connection was mostrecently determined is repeated for the next rule type in order until arule type changed before the handling of the session of the packet wasmost recently determined, at which time the handling of the packet isterminated.

Optionally, only some types of rules are taken into consideration insetting the time at which a rule type was updated. In some embodiments,rule engine 20 is configured to handle rules of different types, such asuser rules which are generally configured by human users and have a lowupdate rate and dynamic rules which are generated automatically and havea high update rate. Optionally, only user rules are taken intoconsideration in setting the most recent update of a rule type. Dynamicrules generally relate to recently created connections and the handlingof previously established connections is not expected to change due toan update of a dynamic rule.

In some embodiments, a special rule type is defined for dynamic ruleswithout relation to the user rules. That is, different rule types aredefined for dynamic rules and for user rules and even if a dynamic ruletype and a user rule type relate to the same fields they are not merged.While these embodiments may increase the number of rule types for whicheach packet need to be scanned, they simplify the operation of ruleengine 20.

Alternatively or additionally to checking for rules updated since thedetermination performed for the connection of the packet, packet filter24 checks in the rematch act 335 for packets belonging to connectionsestablished before a predetermined time. For example, packet filter 24may identify packets whose connection was established before about asecond and lookup stages 308 may be performed for the packet in order toconfirm stability of the previous determination for the connection. Thelookup stages performed in confirming stability may relate to all ruletypes or may be limited only to rule types including dynamic rules. Insome embodiments, table 230 lists for each connection whether it belongsto a dynamic connection and the lookup stages performed for stabilityconfirmation are performed only for connections identified as dynamic.The use of separate rule types for dynamic rules allows performing thestability confirmation lookup only for rule types relating to dynamicrules.

Alternatively to using rule update list 232, whenever a rule is updatedtable 230 is emptied. Further alternatively, whenever a rule is updated,table 230 is reviewed and packet connections matching the updated ruleare removed from table 230.

In some embodiments of the invention, table 230 additionally indicatesfor each connection a time at which the entry for the connection is toexpire, regardless of whether any rules changed. Each time the table isaccessed, packet filter 24 verifies that the accessed entry of the tableis still valid. Optionally, the expire time is determined from rulerecord 272 and/or from an entry in hash table 214. For example, whenconfiguring rules, an expiry time may be associated with the rule,according to an expected life of the rule.

Lookup States

In some embodiments, lookup stages 308 for each rule type include atleast one preliminary lookup stage in which access is made to a Bloomfilter 216 and at least one later stage in which access is made to ahash table 214. The Bloom filter 216 is used for coarse filtering inorder to speedily eliminate packets which clearly do not match any ruleof the rule type and the hash table 214 is used for a fine tuning. It isnoted that further fine tuning may be performed in the further tests(316) indicated by the rule record 272.

This option is optionally used when the percentage of packets expectedto meet rules is very low, such that the Bloom filter 216 is expected toreject a large percentage of packets, optionally at least 90%, 99% oreven at least 99.9%. In some embodiments, only a single lookup stagethat accesses a Bloom filter 216 is used, and the rest of the lookupstages 308 access hash tables. In other embodiments, a plurality ofaccesses to a single Bloom filter 216 or to a plurality of differentBloom filters, are used. For example, for a specific rule type, rulemanager 22 may determine that three fields 208 should be used in anelimination stage. The three fields 208 may be checked in a singleelimination stage including a single access to Bloom filter 216 or inthree separate accesses to the Bloom filter 216.

Optionally, each lookup stage 308 in a sequence of stages for a singlerule type uses a different key 210 formed of different fields. In someembodiments, the keys 210 are totally different and do not include anycommon fields. Alternatively, two or more stages 308 use different keys210, but the keys 210 have one or more fields in common. Furtheralternatively, two consecutive lookup stages 308, a first stage 308accessing a Bloom filter 216 and a second stage 308 accessing a hashtable 214, use the same key 210.

In some embodiments, a single access to a hash table 214 is performed intwo steps. In a first step, the accessed entry is checked in a mannersimilar to that performed in a Bloom filter, without checking whetherthe accessed entry matches the hash key 212 used in accessing the entry.Only if it is determined that the entry corresponds to one or more rulesis the key checked for a match. Thus, the advantage of elimination by aBloom filter is achieved without adding an additional hash lookup stage(308). In one embodiment, only a single lookup stage 308 of this type isused for each rule type and a Bloom filter 216 separate from hash table214 is not used at all. This reduces the memory requirements of packetfilter 24 and/or the number of memory accesses performed by packetfilter 24.

In some embodiments, all rule types involve the same number of lookupstages (308), for simplicity of operation of packet filter 24. Inaccordance with one embodiment, only a single lookup stage is used forall rule types and all additional tests are performed in the furtherhandling (312) indicated in the rule record 272. Alternatively,different rule types may correspond to different numbers of lookupstages (308) so as to better accommodate the rules corresponding to therule type.

Rule Types and Keys

The rule types are optionally defined according to the fields 208 of thepacket to which they pertain. Each rule type pertains to a specific setof fields of the packets and these fields are included in the key 210prepared for the rule type or keys 210 when the rule type corresponds toa plurality of lookup stages (308). For example, a first rule type mayinclude fields which depend on IP 5 tuples (e.g., source and destinationaddress, source and destination port and protocol), a second rule typedepends on VLAN and destination address fields and a third rule typedepends on a URL field.

In some embodiments, lookup key 210 is formed only of one or more fields208 of the packet 220. In other embodiments, the lookup key 210 of oneor more rule types and/or one or more lookup stages (308) includes oneor more result fields 218 in addition to, or instead of fields 208 takendirectly from the packets 220. Each result field 218 includes the resultof applying one or more operators 250 to one or more fields 208. The useof result fields 218 allows checking inequalities and being withinranges, as well as complex conditions such as a plurality of equalitiesand/or inequalities connected by OR or XOR operators.

Alternatively or additionally, lookup key 210 includes one or moreexternal fields, such as a time related field (e.g., day of week, day ofmonth, time of day, indication of day or night).The rule types generallyrelate to layer-3 or layer-4 fields of the packets, but mayalternatively or additionally relate to layer-2 fields and/or to higherlayer fields. The fields used may include, for example, source anddestination addresses and ports, application classifications of thesession of the packet, VLANs, URLs, subnets of source and destinationand tunneling parameters.

Typical rules may include, for example:

-   -   1) Source IP or Destination is equal X    -   2) Destination port=25 (SMTP)    -   3) Source IP=X and Destination port=80 (Web traffic of specific        person)    -   4) Source IP=X and PORT=80 and URL=gmail.com    -   5) Source IP=X and application is NOT a point to point (P2P)        application    -   6) Source or destination subnet=X.Y.Z.00 and PORT=25 (source or        destination) and VLAN=Y

In some embodiments, the key 210 has the same length for all the ruletypes, for example at least 8 bytes, at least 16 bytes or even at least32 bytes. In one embodiment, the key 210 has a length of 32 bytes.Alternatively, the key 210 has a different length for each rule type,depending on the specifics of the rule type.

It is noted that rule engine 20 may be configured with rules relating tosubstantially any of the fields 208 of the packets. Optionally, ruleengine is configured with rules pertaining to more than 20 differentpacket fields, more than 30 different fields, more than 40 differentfields or even more than 50 different fields. Generally, each rulerelates to no more than 5 or 10 fields, but in some cases a single rulemay pertain to more than 20 or even more than 30 different fields.

Hash Table

The hash function Hash1( ) used in generating hash key 212 may be anysuitable hash function known in the art, such as a CRC-32 hash functionor a function which breaks key 210 into segments (e.g., byte segments)and combines the segments using a XOR operator and shift operations.

In an example embodiment, the first hash function Hash1( ) converts key210 into a number including between 6-18 bytes, for example 12 bytes.Optionally, hash key 212 includes in addition to the hashed value of key210, one or more fields which identify the rule type and/or the fieldsof the key structure of the rule type which are currently used. Forexample, hash key 212 may include 24 bytes: 12 bytes resulting from ahashing of key 210, 8 bytes which identify the fields being used andanother 4 bytes which identify the rule type. A second hash functionHash2( ) is optionally used in accessing hash table 214 or Bloom filter216 with hash key 212. The second hash function Hash2( ) results in atable-access number having a number of bits matching the size of thehash table, for example about 24 bits.

Optionally, instead of holding key 210 in the hash table to verify thatthe record reached in a lookup is the intended record, key 212 is heldin the record. Using key 212 has the advantage that it is generallysmaller than key 210 and requires less memory and also that it has afixed size. In some embodiments, key 212 is large enough such that thechances of a mistaken match of the key 212 of a packet to the key 212 ofa record of the hash table are negligible. Alternatively oradditionally, a further match verification is performed in the furthertests (316) after reaching rule record 272.

In some embodiments, the second hash key used to access bloom filter 216is calculated directly from key 210, without calculating the first hashkey 212. Optionally, only if accessing hash table 214 along with acomparison to a hash key of the accessed record in the table isrequired, first hash key 212 is calculated.

In some embodiments, hash table 214 comprises an array 280 of pointers.Each entry 282 in array 280 is optionally a four byte pointer fieldwhich either has a null value, indicating there are no correspondingrules or includes a pointer to a linked list 286. The term pointer isused herein to refer to any data unit which indicates a memory locationand includes absolute address values and relative offsets.

The linked list 286 includes one or more records 284 which each includea corresponding hash key for verification that the packet matches therecord, and further handling instructions. The further handlinginstructions optionally include a pointer to a rule record 272 orinformation directing to a next lookup stage 308. Optionally, the numberof entries 282 in array 280 of hash table 214 is relatively large, suchthat at least 90%, 95% or even 99% of the entries 282 are expected tohave null values.

Bloom Filter

Bloom filter 216 optionally includes a Boolean table which indicates theresult of the lookup stage 308. If the Boolean table location isnegative (e.g., null), the possibility of a match is excluded. If, onthe other hand, a match is found, packet filter 24 proceeds to the nextlookup stage (308).

Each entry of the Boolean table is optionally represented by a smallnumber of bits (e.g., a single bit), such that the entire Boolean tablecan be held in a small memory area and the number of entries in Bloomfilter 216 may be made large, increasing the percentage of rules whichare excluded in an early stage. In addition, using a small memory areafor the Bloom filter 216 may increase the chances of accessed entriesbeing found in cache 28, thus reducing the number of memory accesses. Insome embodiments, packet filter 24 is configured to keep the entries ofBloom filter 216 permanently in cache memory 28 or at least to givepriority in using cache 28 to the Bloom filter. This could substantiallyreduce the number of memory accesses, which are generallytime-consuming, required by packet filter 24.

Alternatively, to a Boolean table, Bloom filter 216 may include in eachentry a multi possibility value, for example a four bit or 8 bitinteger, which includes additional information for cases in which thepacket is not excluded. For example, the value 0 may be used to indicatethat the packet does not have any matching rules, while the other valuesindicate the fields 208 to be used in determining whether the packet hasa possible matching rule. In some embodiments, the entry value in Bloomfilter 216 indicates a sub-group of the fields indicated in the keystructure 206 corresponding to the rule type, to be used in the nextlookup stage 308. Alternatively or additionally, the value from theBloom filter 216 indicates fields 208 to be used, beyond those includedin the key structure. Optionally, in these embodiments, instead of usingthe key structure 206 in generating the key 210 for the next lookupstage 308, the key 210 is generated based on the value in the entry ofthe Bloom filter 216.

For example, the key 210 used in accessing the Bloom filter 216 may bebased only on the destination IP address. The entry in the Bloom filter216 indicates which additional fields 208 are to be used in the key 210used in the next lookup stage 308. For example, the code “01” mayindicate using also the destination port, the code “02” using also theVLAN, the code “03” using both the destination port and the VLAN, thecode “04” using an encapsulated IP address, etc.

The number of entries in the table of the Bloom filter 216 is optionallyselected so that at least a predetermined percentage of the entries(e.g., at least 80%, at least 95% or even at least 99.9%), are null.Alternatively or additionally, the number of entries in the table of theBloom filter 216 is optionally selected such that at least apredetermined percentage (e.g., at least 90%, at least 95% or even atleast 99.9%) of the received packets that do not correspond to rules areexcluded by the lookup in the Bloom filter 216.

In some embodiments, the Bloom filter 216 is accessed using only asingle hash function (i.e., k=1). Alternatively, the bloom filter 216 isaccessed with a plurality of hash functions, for example at least fiveor even at least 10. The number k of hash functions used is optionallyselected based on the configuration parameters of packet filter 24, suchas the number of entries in Bloom filter 216 and the time required foreach access to the Bloom filter 216. If the accesses to the Bloom filter216 are relatively slow, a low value of k, optionally k=1, is preferred.If, however, the accesses are relatively fast and the number of entriesis relatively small, a higher value of k is selected.

In another embodiment, the values in the entries of the Bloom filtercomprise a number of bits, but in accessing an entry only a sub-group ofthe bits, possibly only a single bit, is used. This allows, for example,easily changing the results from Bloom filter 216 over time and/or othercurrent conditions. Optionally, in accessing Bloom filter 216, the exactbit or bits to be looked at is determined according to the time of dayand/or according to a time counter 260 of packet filter 24. For example,each entry may have eight bits, seven bits corresponding to the days ofthe week and an eighth bit for night hours. This allows settingdifferent rules for different days of the week and/or hours of the day.In another example, different bits are used to represent different hoursof the day.

It is noted that in some embodiments, packet filter 24 sequentially goesthrough lookup stages (308) for the different rule types, as illustratedby FIG. 3. In other embodiments, packet filter 24 may handle a pluralityof rule types in parallel, for example managing a plurality of contextsby a single processor or by a plurality of processors which operate inparallel.

Rule Compilation

FIG. 4 is a flowchart of acts performed by rule manager 22 in compilingrules, in accordance with an embodiment of the disclosure.

Reference is also made to FIG. 5, which illustrates a rule 500, handledby rule manager 22, in accordance with an embodiment of the disclosure.Each rule 500 comprises a condition 502 and a task 504 to be performedon packets meeting the condition 502. The condition 502 comprises one ormore terms connected by the logical AND operator 508. The terms may besimple terms 510 (marked also 510A, 510B) or complex terms 512 formed ofa plurality of simple terms 510 connected by logical terms such as OR orXOR. Each simple term 510 may be an equality term 510A or a non-equalityterm 510B, which may include, for example, an inequality (e.g., >, <,<=, >=), range, mask, or searching for a pattern in a field 208.

In the method of FIG. 4, rule manager 22 receives (402) a set of ruleswhich are to be enforced by rule engine 20 and accordingly defines (404)a set of rule types. The definition includes for each rule type, thefields 208 and operators 250 used in the key (or keys) 210 of the ruletype.

Thereafter, for each rule, rule manager 22 selects (406) a rule typewhich best matches the rule. Rule manager 22 determines (407) based onthe matching rule type, which terms (510, 512) of the rule are handled,at least partially, by lookup stages 308 and which are handled entirelyby further tests 316.

For the terms handled by lookup stages 308, rule manager 22 optionallydetermines (408) the entries of hash table 214 and/or Bloom filter 216which will be accessed by packet filter 24 in the process of handlingthe selected rule type, for packets that may match the rule. For eachdetermined entry, rule manager 22 determines (410) the content thatneeds to be placed in the entry (e.g., entry 282 and record 284 of hashtable 214) in order to direct packet filter 24 to a next lookup stage308 or to a rule record 272 generated for the rule in rule database 270.Depending on the rule type, the entry content may merely include a matchindication or may indicate fields 208 and/or operators 250 to be used ina next lookup stage 308. For the last (or only) lookup stage 308 in asequence, the entry indicates the rule record 272 corresponding to therule.

The required content of the rule record 272 corresponding to the rule isdetermined (412). The rule record 272 includes any further tests (316)that need to be performed and the handling that needs to be applied(314) to packets matching the rule. The further tests 316 include termsnot handled by lookup stages 308 and/or fine tuning for terms handledonly approximately by a lookup stage 308. For example, if a rulerequires checking that X>=52 and the lookup stage uses an operator 250of X>=50, the further tests include a verification that X>=52. Thecomplexity of further tests 316 is generally not an issue, since thenumber of packets that reach the stage of the further tests is generallyvery small, such that the processing time spent on these packets isconsidered negligible.

In some embodiments, the further tests 316 prescribed by one or morerule records 272 direct back to one or more lookup stages 308. Thus, acomplex test may be performed between two lookup stages 308. Forexample, if many rules having one or more common attributes compare afield 208 to different values using inequalities, a first lookup stage308 may identify the rules having the one or more attributes and directthem to a rule record 272 which directs the complex test. The rulerecord 272 in such case does not include handling instructions for allthe rules matching its condition. Generally, packets referred back toperform an additional lookup stage 308 will return to a different rulerecord 272 where the handling instructions are located.

After rule manager 22 determines required changes in the database ofpacket filter 24, rule manager 22 updates (414) the database in memory26.

In some embodiments, the method of FIG. 4, including the defining ofrule types (404), is performed periodically. When rule manager 22 isconfigured with new rules, the rules are accumulated until a next timethe method of FIG. 4 is performed. Alternatively, between periodicdefining of rule types, rule manager 22 receives rules and immediately,or periodically at relatively short intervals, updates the database forthe rule, based on the current rule types. In still other embodiments,the defining (404) of rule types is performed only once, atinstallation. Another possibility used in some embodiments is thatduring selection (406) of rule types best matching newly received rules,rule manager 22 generally uses the current rule types, but may initiatechanging of one or more rule types when such a change is determined tobe useful. For example, rule manager 22 determines cases in which thedifference between a new rule and the closest rule type is too large andinitiates a changing of the rule types is such cases. Anotherpossibility is that the definitions of the rule types are revisitedwhenever a new rule that does not match any of the current rule types isreceived.

The changing of the rule types may be limited to defining a new ruletype or changing a single existing rule type so that it matches therule. It is noted that when a rule type is changed, all the rulesmatching that rule type are optionally revisited to make sure they matchthe changed definition of the rule type. Alternatively, the changing ofthe rule types includes initiating a complete process of selection fromscratch of the rule types to be used and accordingly a redefinition ofthe compilations of the rules.

Defining Rule Type Set

Referring in detail to defining (404) a set of rule types, in someembodiments, a predetermined set of rule types is used. Alternatively,the set of rule types is generated responsively to the received set ofrules. In one embodiment, the defined set of rule types includes aseparate rule type for each distinct set of fields related to by one ormore rules. Alternatively, in order to reduce the number of rule types,one or more rule types in the defined set includes a limited set offields serving as a common denominator of a plurality of different setsof fields related to by rules in the rule set. For example, for a ruleset including one or more rules relating only to an IP source field, oneor more rules relating to the IP source field and port source field andone or more rules relating to the IP source field and a VLAN field, asingle rule type may be defined for the IP source, which rule type isintended to cover rules of any set of fields including the IP sourcefield.

Optionally, rule manager 22 determines groups of conditions which areshared by large sub-sets of rules in the rule set and defines rule typesfor these groups of conditions. In some embodiments, rule manager 22estimates, for each condition term 510 or 512, the percentage of packetsthat can be filtered out by the term. Particularly, rule manager 22optionally estimates the probability of occurrence of false positivematches for rules, for various fields and defines rule sets, which areexpected to achieve lowest false positive match rates. In someembodiments, fields having an expected higher distribution of values arepreferred in being included in the rule sets.

The estimation is optionally based on pre-configured statistics for thevarious possible fields related to in the terms. Alternatively, theestimation is based on a current set of rules being considered.Optionally, the estimation is based on the particular values to whichthe fields are compared in the terms. For example, low port values aregenerally very common and therefore their filtering value is low, whilehigh port values are relatively rare and their filtering value is high.The estimation of the percentage of packets filtered by terms relatingto a port field is optionally based on the number or percentage of rulesthat relate to high port values.

Rule types are optionally defined for sets of terms that are expected tofilter out a large percentage of the packets. It is noted that equalityterms 510A can separately filter out each of the possible values of afield 208. In contrast, other terms, which involve operators 250,perform the filtering only for a single value included in the operator.For example, an inequality term 510B relating to a field 208 of a valueX, relates to a specific value, such as X>5. In order to compare toanother value, e.g., X>20, using the hash table lookup, another operator250 and corresponding field in key 210 are required.

The rule types are optionally determined in a manner which minimizes thepercentage of packets being false positives, that is packets that aredirected in the lookup stages (308) to rule database 270 but do notcorrespond to a rule. This is optionally achieved by having the ruletypes cover the rules relatively closely.

On the other hand, the rule types are optionally determined in a mannerwhich minimizes the processing time that needs to be spent on filteringeach packet, for example by minimizing the number of operators 250, thenumber of memory accesses performed by the rule type and/or the numberof rule types.

Optionally, the generation of the rule types takes into account thepossible values of the different fields 208, for example preferringrules relating to fields having a larger number of possible valuesand/or a relatively low frequency for any specific value. For example,rules relating to an IP address field are optionally preferred overrules relating to TCP port, as many packets have the same port value.Optionally, rule manager is configured with the possible values of eachfield 208 and/or with estimated frequencies of the values of the fields.

In some embodiments, rule manager 22 defines rule types only based onequality terms 510A, and all other terms are handled in further tests316. In other embodiments, when a very popular non-equality term 510B or512, which can add substantially to reducing the number of falsepositives, is identified, an operator 250 for the term is defined andthe term is included in one or more of the rule types.

Rule types optionally include only a single operator 250 for a field208. Alternatively, a rule type may include a plurality of operators fora single field 208, for example comparing the field to different values.In some embodiments, the plurality of operators may even includecontradicting conditions. For example, a rule type may include a firstoperator 250 for X<20 and a second operator 250 for X>30, for the samefield 208 X. The inclusion of the plurality of operators in the samerule type, reduces the number of rule types required.

Optionally, when an operator 250 is defined for an inequality for afield 208 that is compared in different rules to different values, asingle value or several values are selected to represent a larger numberof values in the rules. For example, if a field 208 (X) is compared witha “smaller than or equal” operator (<=) in different rules to the values55, 57, 59, 60 and 89, two operators 250 may be defined: X<=60 andX<=89. Rules requiring a comparison X<=57 are translated to the X<=60operator 250 and the verification that X is smaller than 57 is performedin the corresponding record 272 in the further tests (316).

In some embodiments, the defining of rule types begins with a beginningset of rule types, for example including between 1-4 rule types. Therule types in the beginning set may be predetermined, or may be selectedbased on the current set of rules of rule engine 20. Optionally, therule types in the beginning set are single term rule types, for the mostprevailing terms. Alternatively or additionally, the beginning set ofrule types includes a minimal set of single term rule types, whichcorrespond to all rules currently handled by rule engine 20, such thateach rule relates to at least one field of the set of single term ruletypes. The minimal set is optionally selected by selecting the fields208 not yet included in the set, which relate to the largest set ofrules not yet corresponding to a rule type in the set. Alternatively oradditionally, a plurality of sets are contemplated and the set with thesmallest number of rule types is selected.

Optionally, after defining the beginning set, an iterative process isperformed in which a current set, initialized with the beginning set, isupdated. Optionally, in each iteration, each of the rules is classifiedto one of the rule types in the current set and a difference between therule and the rule type is evaluated. For rule types having a largeaccumulated difference, rule manager 22 determines an additional ruletype which could remove a substantial number of rules from the rule typewith the large accumulated difference, in a manner which minimizes thesum of the accumulated difference of both the old and new rule types.The new rule type is added to the current set if the cost of adding theadditional rule type in terms of processing power of packet filter 24 isfound to be smaller than the cost of the accumulated difference. The newrule type may be generated, for example, by adding a term to the oldrule type and/or by removing a term. In other embodiments, a new ruletype is defined when a rule is found to be farther than its closest ruletype by at least a predetermined extent.

Optionally, the number of rule types is limited to a maximal number, forexample 10 or 15. Alternatively, the number of rule types is notlimited. Optionally, the addition of each rule type is required toachieve a total gain in processing resources. In determining whether toadd a rule type, rule manager 22 optionally estimates the percentage ofpackets which will be rejected earlier (e.g., before reaching a record272) due to the addition of the rule type.

While in some embodiments the selection of rule types is entirelyautomatic, in other embodiments the selection is performed partially orentirely by a human.

Rule manager 22 optionally determines the number of lookup stages to beused for each rule type. Optionally, rule manager 22 estimates theprocessing power required for each number of lookup stages and selectsthe most efficient number of stages. In embodiments in which all therule types are required to have the same number of lookup stages, aminimization over all the rule types is optionally performed. Inembodiments in which a maximal number of allowed stages is defined, onlysequences including the allowed number of stages is considered.

Handling Rules

As to selecting (406) a rule type which best matches the rule, rulemanager 22 optionally compares the rule to each rule type and determinesthe rule type for which the percentage of false positives is lowest.Optionally, a rule is not assigned to a rule type that relates to afield 208, not related to by the rule. Alternatively, if the possiblenumber of values of the field 208 included in the rule type but not inthe rule is relatively small and the advantage from matching the ruletype for the rule is relatively high, the rule type is used. Forexample, when results of operators 250 are Boolean, a rule type mayrelate to several operators 250 although rules matching the rule typeonly relate to a sub-group, possibly only one or none, of the operatorresults.

As to determining (410) the content that needs to be placed in theentry, when the rule type has only a single lookup stage 308, the entrydirects to the corresponding record 272. When a plurality of lookupstages are used, the non-last stages optionally return a Boolean answeras to whether a match is found. Alternatively, the entry of one or morelookup stages 308 may indicate the fields 208 to be used in the key 210of the next stage. A key structure 206 is optionally defined for eachlookup stage of the rule type.

As an example, if rule manager 22 is configured with several rulesrelating to source IP address (IP_(src)), source port (Port_(src)) andpossibly another field, the rule type may correspond to two lookupstages 308. In a first stage, a lookup is performed based on IP_(src)and Port_(src), and the results of the lookup direct to a rule record272, direct to another lookup stage or provide a negative answer,depending on the values of IP_(src) and Port_(src). For example, giventhe following rule conditions:

a) IP_(src)=123 AND Port_(src)=456 AND IP_(dst)=789

b) IP_(src)=123 AND Port_(src)=654 AND VLAN=62

c) IP_(src)=346 AND Port_(src)=291

d) IP_(src)=444 AND Port_(src)=111 AND Port_(dst)<291

the hash table entry corresponding to the IP_(src) and Port_(src) valuesof a, would lead to a further lookup based on IP_(dst), and the hashtable entry corresponding to the IP_(src) and Port_(src) values of b,would lead to a further lookup based on VLAN. The hash table entrycorresponding to the IP_(src) and Port_(src) values of c and d, wouldlead directly to respective corresponding rule records 272 and othervalues would provide a negative answer indicating there are no matchingrules. It is noted that the rule record 272 of c merely states thehandling of the packet, as any packet reaching this record 272 matchesthe rule. In contrast, the rule record 272 of d includes a verificationinstruction, which verifies that the packet meets Port_(dst)<291 beforemoving on to the handling of the rule record 272.

As to determining (412) rule record 272, when more than one rule isdirected to the same rule record 272, the further tests (316) prescribedby the rule determine which of the rules is met, if any. In such case,the portion of the record 272 indicating the handling that needs to beapplied (314) to packets matching the rule may include several differenthandling methods, for the different matching rules.

Database Update

The operation of rule manager 22 provides for each new or changed rule,required updates to hash table 214 and/or Bloom filter 216. In addition,for at least some rules, a record 272 needs to be generated or updated.Also, changes to the rule types require changing type-records 204 and/orkey structures 206.

The updating (414) for a batch of a plurality of new rules receivedtogether may be performed together, after determining the requiredchanges for all the new rules. Alternatively, after determining therequired updates for a rule, the updates are performed immediately andthen the updates required for a following new rule are determined.

In updating (414) the database of packet filter 24 for rules beingadded, rule manager 22 optionally performs the updating in a mannerwhich allows packet filter 24 to continue operating during the updating.Optionally, packet filter 24 does not write to hash table 214 and/orBloom filter 216, such that a write collision between rule manager 22and packet filter 24 is not possible.

In adding a new rule, rule manager 22 optionally first generates record272 of the rule and records 284 in hash table 214. These data elementsare not yet accessible by packet filter 24 as there is no pointer entry282 leading to them. If a rule hash table record 284 for the rulealready exists (e.g., due to a similar rule previously configured intopacket filter 24), rule manager 22 optionally generates a new record 284and then changes the pointer entry 282 to lead to the new record 284 anddeletes the old record 284. Similarly, in some embodiments, any time achange to a record 272 is required, rule manager 22 prepares a newrecord in a memory location not accessible by packet filter 24 becauseit is not on any linked list 286. Then, in an atomic operation, e.g., ashort memory write, the new record 272 is linked to from an entry ofHash table 214, in a process that does not allow collisions.

Changing to hash table entries 284 and entries of Bloom filter 216 areoptionally performed in a manner which reduces the chances of acollision. Optionally, the entries are updated from the last lookupstage 308 to the first lookup stage.

When changing a rule type, new records may be required for all the rulesof the rule type. Optionally, new records are generated for the rulesand then the pointers are updated sequentially from the old recordswhich are still in use, to the new records. After all the relevantpointers were changed, the old records are deleted.

If the change in the rule type is performed because of a new rule, thenew rule may be first configured into packet filter 24 based on an oldrule type, even if inefficient and then the change of the rule type isorganized. This allows immediate implementation of the new rule withoutrequiring waiting for changes in a rule type, which may be timely.Alternatively or additionally, packet filter 24 is configured to testpackets for a limited pool of rules using prior art methods and ruleswaiting for changes in a rule type are included in the limited pool.

Updating (414) packet filter 24 for a rule, optionally includes listingthe change in rule update list 232. Erasing a rule from packet filter 24optionally includes erasing the rule from rule update list 232.Optionally, rule manager 22 does not change existing rules in packetfilter 24, due to the complexity of such an update. Instead, a new ruleis updated into the database of packet filter 24 and the old rule isremoved. In some embodiments, rule manager 22 manages an internaldatabase, listing for each rule how it was implemented in memory 26.When the rule needs to be removed, rule manager 22 can use theinformation in the internal database to quickly cancel the rule.

When a rule is removed and the rule is the last rule of a rule type,rule manager 22 optionally cancels the rule type by removing itstype-record 204.

Optionally, packet filter 24 is configured to check for all the rulesusing hash table lookups. Alternatively, when rule engine 20 isconfigured in addition to a large number of rules handled by lookuptables, with a small number of other rules having different formats fromthe rest of the rules, the small number of rules may be implementedusing other filtering methods, without table lookups. In such cases, foreach packet, packet filter 24 performs table lookups for one or morepacket types and also checks the other rules using other filteringmethods.

Rule manager 22 may relate to all rules in a similar manner.Alternatively, rule manager 22 may handle different rules differently.For example, rule manager 22 may be configured to handle different ruleswith different priorities. Some rules may be considered of high prioritymeaning they must be configured into packet filter 24 within a shortperiod, for example less than 1 second, while other rules may requireconfiguration within less than a minute or only less than 10 minutes,allowing rule manager 22 to configure a plurality of rules together. Insome embodiments, rule manager 22 handles separately human-specifiedrules and automatically generated rules. Optionally, each is assigned adifferent set of one or more rule types.

It is noted that in some embodiments the access to memory 26 is expectedto be the most time consuming act of packet filter 24. Accordingly,various memory access optimization methods known in the art may be usedto speed up the operation of packet filter 24. For example, variousvalues accessed in the memory may be set to sizes which are easy toaccess (e.g., 32 bytes).

In the above description, the contents of the hash table entries have asingle value which directs the further handling of the packet. In someembodiments, however, the result in the hash entry comprises a pluralityof values corresponding to different conditions, such as different timesof day or different times from configuration of the rule. In theseembodiments, in each lookup, the value of the entry corresponding to thecurrent conditions is used. This allows configuring the rule engine withrules applying only to specific conditions.

The term “real time” refers herein to tasks being performed shortlyafter instructions to perform the task are received, for example withinless than 10 minutes, less than 10 seconds or even less than 50milliseconds.

While the above description relates primarily to finding matchingrecords for lookup keys using Hash tables, in other embodiments of theinvention other data structures are used, such as a Trie, also known asa prefix tree and/or a TCAM (Ternary content addressable memory) or anEGT-PC (Extended Grid of Tries with Path Compression). In someembodiments, a plurality of different types of data structures are used.For example, in one embodiment, a Trie is used for a first lookup stageand a TCAM and/or Hash table is used for subsequent lookup stages. Inanother embodiment, in traversing the Trie, encountered nodes indicate ajump to a different node, depending on the values of the fields of thepacket used to reach the node.

Conclusion

It will be appreciated that the embodiments described above are cited byway of example, and that the present disclosure is not limited to whathas been particularly shown and described hereinabove. Rather, the scopeof the present disclosure includes both combinations andsub-combinations of the various features described hereinabove, as wellas variations and modifications thereof which would occur to personsskilled in the art upon reading the foregoing description and which arenot disclosed in the prior art.

The invention claimed is:
 1. A method of configuring a packet filter toscreen data packets, the method comprising: receiving, by a rule managerprocessor, a set of packet filtering rules, wherein each rule includesone or more terms connected by a logical operator; generating a set ofrule types by the rule manger processor responsive to the received setof rules, wherein each rule type corresponds to a set of data packetfields such that each of the rules in the set of rules belongs to atleast one rule type of the set of rule types; selecting, by the rulemanager processor, for each rule a respective rule type of the set ofrules which best matches the rule, and then based on the matching ruletype, determining by the rule manager processor which terms of theselected rule are to be handled by lookup stages and which terms of therule are to be handled by further tests; and updating, by the rulemanager processor, entries in a data structure stored in memory inaccordance with the lookup stages and the further tests of the selectedrules, wherein the data structure comprises a hash table that isaccessible by a packet filter that generates one or more first lookupkeys to screen a received data packet, wherein at least one entry in thearray of pointers is a four byte pointer field that includes a pointerto a memory location of a linked list, wherein linked list includes oneor more records which each include (a) a corresponding hash key forverification that a received packet matches the record, and (b) furtherhandling instructions, wherein at least some of the records in the datastructure indicate a second one or more lookup keys to be used in one ormore respective further accesses to the data structure by the packetfilter.
 2. The method of claim 1, wherein generating the one or morefirst lookup keys comprises generating at least one first lookup keybased on a plurality of fields of the packet.
 3. The method of claim 1,wherein at least some of the records in the data structure indicate aplurality of second lookup keys to be used in a further access to thedata structure.
 4. The method of claim 1, wherein at least one firstrecord indicates a single second lookup key and at least one secondrecord indicates a plurality of second lookup keys.
 5. The method ofclaim 1, wherein the data structure further comprises a TRIE.
 6. Themethod of claim 1, wherein the data structure further comprises a TCAM.7. The method of claim 1, wherein accessing the data structure comprisesaccessing a bloom filter which is a part of the data structure.
 8. Themethod of claim 1, wherein generating for each received packet one ormore first lookup keys comprises generating for one or more packets aplurality of different first lookup keys.
 9. The method of claim 8,wherein the accesses to the data structure for the plurality ofdifferent first keys of the packet are performed for all the first keyseven if a matching rule was already found for the packet.
 10. Anon-transitory computer readable medium having instructions storedthereon for configuring a packet filter to screen data packets that,when executed by a rule manager processor, direct the rule managerprocessor to: receive a set of packet filtering rules, wherein each ruleincludes one or more terms connected by a logical operator; generate aset of rule types responsive to the received set of rules, wherein eachrule type corresponds to a set of data packet fields such that each ofthe rules in the set of rules belongs to at least one rule type of theset of rule types; select for each rule a respective rule type of theset of rules which best matches the rule, and then based on the matchingrule type, determine which terms of the selected rule are to be handledby lookup stages and which terms of the rule are to be handled byfurther tests; and update entries in a data structure stored in memoryin accordance with the lookup stages and the further tests of theselected rules, wherein the data structure comprises a hash table thatis accessible by a packet filter that generates one or more first lookupkeys to screen a received data packet, wherein at least one entry in thearray of pointers is a four byte pointer field that includes a pointerto a memory location of a linked list, wherein linked list includes oneor more records which each include (a) a corresponding hash key forverification that a received packet matches the record, and (b) furtherhandling instructions, wherein at least some of the records in the datastructure indicate a second one or more lookup keys to be used in one ormore respective further accesses to the data structure by the packetfilter.
 11. The non-transitory computer readable medium of claim 10,wherein generating the one or more first lookup keys comprisesgenerating at least one first lookup key based on a plurality of fieldsof the packet.
 12. The non-transitory computer readable medium of claim10, wherein at least some of the records in the data structure indicatea plurality of second lookup keys to be used in a further access to thedata structure.
 13. The non-transitory computer readable medium of claim10, wherein at least one first record indicates a single second lookupkey and at least one second record indicates a plurality of secondlookup keys.
 14. The non-transitory computer readable medium of claim10, wherein the data structure further comprises a TRIE.
 15. Thenon-transitory computer readable medium of claim 10, wherein the datastructure further comprises a TCAM.
 16. The non-transitory computerreadable medium of claim 10, wherein accessing the data structurecomprises accessing a bloom filter which is a part of the datastructure.
 17. The non-transitory computer readable medium of claim 10,wherein generating for each received packet one or more first lookupkeys comprises generating for one or more packets a plurality ofdifferent first lookup keys.
 18. The non-transitory computer readablemedium of claim 17, wherein the accesses to the data structure for theplurality of different first keys of the packet are performed for allthe first keys even if a matching rule was already found for the packet.19. A rule engine comprising: an input interface for receiving packets;a memory unit configured with at least one data structure correlatingbetween packet key values and indications of rules to be applied topackets having the respective key values, wherein for at least somepacket key values the at least one data structure includes an indicationof one or more keys to be used in further access to the data structure,wherein the data structure includes a hash table; a packet filteringprocessing unit configured to receive packets, to generate for eachpacket at least one first lookup key including one or more fields of thepacket, to access the data structure responsive to the generated atleast one first lookup keys, and to perform the further acts indicatedby the data structure for the packet so as to determine whether thepacket matches a rule; and a rule manager processor configured toreceive rules to be implemented by the rule engine and to update thedata structure responsive to the received rules while the packetfiltering processing unit is operative, without locking the memory unitfor access by the packet filtering processing unit.
 20. The rule engineof claim 19, wherein the rule manager processor is configured to dividethe rules into rule types and to configure the packet filteringprocessing unit with instructions on generating the lookup keysaccording to the rule types.